package com.yjc.hire.mq;


import com.rabbitmq.client.impl.nio.BlockingQueueNioQueue;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqSMSConfig {
    public static final String SMS_EXCHANGE = "sms_exchange";

    public static final String SMS_QUEUE = "sms_queue";

    public static final String ROUTING_KEY_SNS_SEND_LOGIN = "hire.sms.send.login";

    @Bean(SMS_EXCHANGE)
    public Exchange smsExchange() {
        return ExchangeBuilder.topicExchange(SMS_EXCHANGE)
                .durable(true)
                .build();
    }

    @Bean(SMS_QUEUE)
    public Queue smsQueue() {
      return QueueBuilder.durable(SMS_QUEUE)
              .withArgument("x-dead-letter-exchange",RabbitMqSMSConfig_Dead.SMS_EXCHANGE_DEAD)
              .withArgument("x-dead-letter-routing-key",RabbitMqSMSConfig_Dead.ROUTING_KEY_SNS_SEND_Dead)
              .withArgument("x-max-length", 1024)
              .withArgument("x-message-ttl", 60000)
              .build();
    }

    @Bean
    public Binding smsBinding(@Qualifier(SMS_EXCHANGE) Exchange exchange, @Qualifier(SMS_QUEUE) Queue queue) {
        return BindingBuilder.bind(queue)
                .to(exchange)
                .with("hire.sms.#")
                .noargs();
    }
}
